import { Component, OnInit, Input, EventEmitter, Output, Host, Inject, forwardRef, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Service } from '../../../server/server';

import { RemoveTableService } from '../../../public/serve/remove-table/remove-table.service';
declare var $: any;

interface Response {
  result: string[];
  result_code: string;
  message: string;
}

@Component({
  selector: 'app-central-delete',
  templateUrl: './central-delete.component.html'
})
export class CentralDeleteComponent implements OnInit {

  constructor(private http: HttpClient, private server: Service, private removeTableService: RemoveTableService) { }

  ngOnInit() {
  }

  @Output()
  deleteOutput: EventEmitter<string> = new EventEmitter();

  // 确认删除
  confirmDel() {
    let body = {
      ids: this.removeTableService.getRemoveTableId,
    }
    let url = this.server.baseUrl + 'Service/Center/deleteCenter';
    //console.log(body)
    this.http.post<Response>(url, body).subscribe(res => {
      this.deleteOutput.emit(res.result_code);
      //console.log(res);
      if (res.result_code == '0000') {
        this.server.prompt = { prompt: true, success: true, fail: false, promptStatement: res.message }
        this.server.promptclose;
        $("#delete").modal("hide");
        this.removeTableService.getRemoveTableId = [];
      }
      else {
        this.removeTableService.getRemoveTableId = [];
        this.server.prompt = { prompt: true, success: false, fail: true, promptStatement: res.message }
        this.server.promptclose;
        $("#delete").modal("hide");
      }
    })
  }

}
